package main

import (
	"fmt"
	"git.inke.cn/bpc/server/sdk/commlib"
	"math/rand"
	"strings"
	"time"
)


func main() {
	s := []string{"aaaa"}
	TestSliceParam(s)
	fmt.Println(s)
}

//检测字符串数组是否会有引用的效果：外面传值，函数里改变，外面是否会改变
func TestSliceParam(s []string) {
	//s = append(s,"ssss")//使用扩容，则次出去的改变无法影响到外面
	s[0] = "ssss"//这里的改变可以影响外面
}

func MicsSlice(origin []int64, count int) []int64 {
	tmpOrigin := make([]int64, len(origin))
	copy(tmpOrigin, origin)
	//一定要seed
	rand.Seed(time.Now().Unix())
	rand.Shuffle(len(tmpOrigin), func(i int, j int) {
		tmpOrigin[i], tmpOrigin[j] = tmpOrigin[j], tmpOrigin[i]
	})

	result :=make([]int64,0,count)
	for index, value := range tmpOrigin {
		if index==count{
			break
		}
		result = append(result,value)
	}
	return result
}


func test33() {
	//测试slice被赋值给变量，改变变量是否会改变slice
	a := []string{"1", "2"}
	sli := a
	sli = append(sli, "j")
	fmt.Println(sli,a)
}

//向数组中间添加元素
func test42() {
	var a = []int{1, 2, 4, 5, 6}
	fmt.Println(a[:2])
	a = append(a[:2], append([]int{3}, a[2:]...)...)
	fmt.Println(a)
}

func testNil() {
	var s []int
	s = nil
	fmt.Println(len(s))
}

//测试切片的截取
func test5() {
	s := []int64{1, 2, 3, 4, 5}
	fmt.Println(s[0:1])
	fmt.Println(commlib.SliceInt642String(s[1:len(s)]))
}

func test4() {
	m := [...]int{
		3: 2,
	}
	fmt.Println(len(m))
}

func test2() {
	resStrList := strings.Split("1322328-477597-1659456000-1643179354", "-")
	fmt.Println(len(resStrList))
}

func test3() {
	var testArray [3]int
	var numArray = [...]int{1, 2}
	var cityArray = [...]string{"北京", "上海", "深圳"}
	fmt.Println(testArray)                          //[0 0 0]
	fmt.Println(numArray)                           //[1 2]
	fmt.Printf("type of numArray:%T\n", numArray)   //type of numArray:[2]int
	fmt.Println(cityArray)                          //[北京 上海 深圳]
	fmt.Printf("type of cityArray:%T\n", cityArray) //type of cityArray:[3]string
}

func qpjq() {
	numbers := []int{0, 1, 2, 3, 4, 5, 6, 7, 8}
	fmt.Println(numbers[:len(numbers)-1])
}

//验证slice经过函数处理后，外部是否会被影响：会受影响
func TestSlice(s []string) {
	s[1] = "ddddddddd"

	s[0] = "11111"

	s[0], s[1] = s[1], s[0]
	fmt.Println(cap(s))
}
